﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Planisoft.Entities;
using Planisoft.BL;
using Microsoft.Practices.Unity;


namespace Planisoft.ClienteMvcWeb.Controllers
{
    public class PlantillaIngresoController : Controller
    {
        //
        // GET: /PlantillaIngreso/
        [Dependency]
        public IPlantillaIngresoBL PlantillaIngresoBL{ get; set; }
        [Dependency]
        public IIngresosPdtSunatBL IngresosPdtSunatBL { get; set; }
        public ActionResult Index()
        {
            var lista = PlantillaIngresoBL.GetAllFromPlantillaIngreso();
            return View(lista);
        }

        //
        // GET: /PlantillaIngreso/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /PlantillaIngreso/Create

        public ActionResult Create()
        {
            var listIngresosPdtSunaId = IngresosPdtSunatBL.GetAllFromIngresosPdtSunat();
            ViewData["IdIngresoSunat"] = new SelectList(listIngresosPdtSunaId, "IdIngresoSunat", "DescIngresoSunat");

            return @PartialView("_Create");
        } 

        //
        // POST: /PlantillaIngreso/Create

        [HttpPost]
        public ActionResult Create(PlantillaIngreso plantillaIngreso)
        {
            try
            {
                // TODO: Add insert logic here
                PlantillaIngresoBL.AddPlantillaIngreso(plantillaIngreso);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /PlantillaIngreso/Edit/5
 
        public ActionResult Edit(int id)
        {
            var plantillaIngreso = PlantillaIngresoBL.GetFromPlantillaIngresoById(id);
 
            var listIngresosPdtSunaId = IngresosPdtSunatBL.GetAllFromIngresosPdtSunat();
            ViewData["IdIngresoSunat"] = new SelectList(listIngresosPdtSunaId, "IdIngresoSunat", "DescIngresoSunat",plantillaIngreso.IdIngresoSunat);
            
            return @PartialView("_Edit",plantillaIngreso);
        }

        //
        // POST: /PlantillaIngreso/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, PlantillaIngreso plantillaIngreso)
        {
            try
            {
                // TODO: Add update logic here
                PlantillaIngresoBL.UpdatePlantillaIngreso(plantillaIngreso);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /PlantillaIngreso/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /PlantillaIngreso/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
